from collections import OrderedDict

from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


def jwt_response_payload_handler(token, user=None, request=None):
    return {
        'token': token,
        'username': user.username,
        'id': user.id
    }


class PageNum(PageNumberPagination):

    page_size = 5
    page_size_query_param = 'pagesize'

    def get_paginated_response(self, data):
        return Response({
            'count': self.page.paginator.count,  # 返回结果的总数量
            'lists': data,  # 当前页面的内容
            'page': self.page.number,  # 当前页码
            'pages': self.page.paginator.num_pages,  # 总共页数
            'page_size': self.page_size,  # 每页多少条记录
        })

